<template>
  <div>
    <div class="select-label">{{ label }}</div>

    <el-select
      v-if="options.length > 0"
      v-model="selected"
      clearable
      placeholder="请选择"
      @change="handleChange"
    >
      <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
      </el-option>
    </el-select>

    <el-input v-else></el-input>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
  components: {},
  props: {
    label: {
      type: String,
      default: 'Label',
    },
    options: {
      type: Array,
      default: () => [],
    },
    value: {
      type: String,
      default: '',
    },
  },
  data() {
    return {}
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('update:value', val)
      },
    },
  },
  methods: {
    handleChange(val) {
      const item = this.options.find((d) => d.value === val)
      this.$emit('change', item)
    },
  },
})
</script>
<style lang="scss" scoped>
.select-label {
  color: #fff;
  margin-bottom: 15px;
}
</style>
